using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Text;

namespace ECCIT.Web.UI.WebControls
{
	/// <summary>
	/// Summary description for ELPButton.
	/// </summary>
	[DefaultProperty("Text"),
      ToolboxData("<{0}:YUIDropDownList runat=server></{0}:YUIDropDownList>")]
	public class YUIDropDownList : System.Web.UI.WebControls.DropDownList
	{
		private string _paddingLeft;
		private string _imgSrc;
		private string _onClick;

		[Bindable(true), 
			Category("Appearance"), 
			DefaultValue("2em")] 
		public string PaddingLeft
		{
			get {return (_paddingLeft==null) ? "2em" : _paddingLeft;}
			set {_paddingLeft = value;}
		}

		[Bindable(true), 
		Category("Appearance"), 
		DefaultValue("")] 
		public string ImgSrc
		{
			get {return (_imgSrc==null) ? string.Empty : _imgSrc ;}
			set {_imgSrc = value;}
		}

		[Bindable(true), 
		Category("Appearance"), 
		DefaultValue("")] 
		public new string OnClick
		{
			get {return (_onClick==null) ? string.Empty : _onClick;}
			set {_onClick = value;}
		}

		/// <summary> 
		/// Render this control to the output parameter specified.
		/// </summary>
		/// <param name="output"> The HTML writer to write out to </param>
		protected override void Render(HtmlTextWriter output)
		{
			// 
//			if (this.Page.IsClientScriptBlockRegistered())
//			{
//				
//			}

			// render style
			StringBuilder styleBuilder = new StringBuilder("<style type=\"text/css\">");
			styleBuilder.Append(".yui-button#").Append(this.ID).Append(" button {\n");
			
			styleBuilder.Append("</style>\n");
			output.Write(styleBuilder.ToString());

			// render control
			output.AddAttribute(HtmlTextWriterAttribute.Id, this.ID);
			output.AddAttribute(HtmlTextWriterAttribute.Type, "Button");
			//output.AddAttribute(HtmlTextWriterAttribute.Value, this.Text);
			//output.RenderBeginTag(HtmlTextWriterTag.Input);
			//output.RenderEndTag();
			base.Render(output);

			// render scripts
			StringBuilder scriptBuilder = new StringBuilder("<script type=\"text/javascript\">\n<!--\n");			
			scriptBuilder.Append("var ").Append(this.ID).Append(" = new YAHOO.widget.Button(\"").Append(this.ID).Append("\");\n");
			if (this.OnClick.Trim() != string.Empty)
				scriptBuilder.Append(this.ID).Append(".on(\"click\", ").Append(this.OnClick).Append(");\n");
			
			scriptBuilder.Append("//-->\n</script>");
			output.Write(scriptBuilder.ToString());
		}
	}
}
